<template>
	<view class="home">
		<view class="user_top">
			<text>会员中心--收货地址</text>
		</view>
		
		<view class="tit"   v-for="item in address" :key="item.id">
			<view class="tit1"><text>{{item.username}},{{item.phone}}</text></view>
			<view class="tit1"><text>{{item.useraddress}}</text></view>
			<view class="tit2">
				<view class="tit2_l">
				 <label class="radio"><radio value="r1" />默认</label>
				</view>
				<view class="tit2_r">
				 <button size="mini" type="default" @click="address_del(item.id)">删除</button>
				 <button size="mini" type="default" @click="address_edit(item.id)">修改</button>
				 </view>
			</view>
		</view>
		
		  <!--添加按钮-->
		  <view class="btn" @click="btn_add">
			  <button size="mini" type="primary" style="background-color: #f47920;width: 100%;margin: 10px;">添加收货地址</button>
		  </view>
		
	</view>
</template>

<script>
	import helper from '.../../common/helper.js';  
	export default {
		data() {
			return {
                username:{},
				products:{},
				address:[],
			}
		},
		onLoad(options) {
		   this.getaddresss()
		},
		methods: {
			//获取地址列表
			async getaddresss () {
				var res = uni.getStorageSync('my_info');

				const res2 = await this.$myRuquest({
					url:'/index/dsnv.activities/address_list',
					data:{
						"uid":res.id,
					},
				})
				
				if(res2.data.code ==200){
					this.address=res2.data.date;
				}else{
					uni.showToast({
						title: res2.data.info,
						duration: 3000,
						icon: 'none'
					})
				}
			
			},
			//删除地址
			async address_del(id) {
				
				const res2 = await this.$myRuquest({
					url:'/index/api/address_del',
					data:{
						"id":id,
					},
				})
				
				if(res2.data.code ==200){
						uni.showToast({
							title: res2.data.info,
							duration: 3000,
							icon: 'none'
						}),
						uni.navigateTo({
							url: '/pages/my/address/address'
						});
				}else{
					uni.showToast({
						title: res2.data.info,
						duration: 3000,
						icon: 'none'
					})
				}
				
			},
			//跳转添加按钮
			async btn_add() {
				var res = uni.getStorageSync('my_info');//读取缓存
					uni.navigateTo({
						url:"/pages/my/address/address_add"
					})
			},
			//跳转修改页面并传参
			async address_edit(id) {
				   console.log(id);
				   uni.navigateTo({
					 url:"/pages/my/address/address_edit?id="+id
				   })
			}
			
			
		}
	}
</script>

<style lang="scss">

	.home{
		height: 600px;
		background-color: #F2F2F2;
		//会员中心
		
		.user_top{
			height: 35px;
			text-align: center;
			padding-top: 8px;
			background-color: #fff;
				}
		.tit{
			margin: 10px;
			padding: 10px;
			background-color: #FFFFFF;
			margin-top: 10px;
			border-radius: 10px;
			.tit1{
				font-size: 15px;
				padding-top: 5px;
			}
			.tit2{
				display: flex;
				font-size: 15px;
				margin-top: 30px;
				.tit2_l{
					margin-top: 1px;
					width: 50%;
					
				}
				
				.tit2_r{
				text-align: right;
				flex: 1;
					
				}
			}
		}
		.btn{
			margin-right: 20px;
		}
		
	}
</style>
